import axios from 'axios';
import router from '../router';
import BASEURL from './helper'

let API_ADDRESS = BASEURL.BASEURL;


const service = axios.create({
    baseURL: process.env.NODE_ENV === 'development'? API_ADDRESS:API_ADDRESS,
    timeout: 5000*10
});

service.interceptors.request.use(
    config => {
        // if(!config.data.isToken || config.data.isToken==='undefined'){
        //     let token = JSON.parse(localStorage.getItem('adminToken')) || '';
        //     if(token){
        //         config.headers.token = token
        //     }else {
        //         Message.error('token为空');
        //         router.push({path:'/login'})
        //         return false
        //     }
        // }
        return config;
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);

service.interceptors.response.use(
    response => {
        if (response.status === 200) {
            return response.data;
        } else {
            Promise.reject();
        }
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);

export default service;
